package com.vd.tbsms.process.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.ss.usermodel.Workbook;

import com.vd.tbsms.Status;
import com.vd.tbsms.parse.XlsParse;
import com.vd.tbsms.process.LoadResProcess;
import com.vd.tbsms.resource.Resource;
import com.vd.tbsms.resource.XlsResource;


/**
 * @desc 加载Excel数据
 * @author tudongyun
 *
 */
public class XlsLoadResProcess implements LoadResProcess {
	private Log log = LogFactory.getLog(XlsLoadResProcess.class);
	private Status status = Status.INIT;
	private String errMsg;
	private XlsParse xlsParse = new XlsParse();
	@Override
	public List<String> getHeader() {
		return xlsParse.getHeaders();
	}

	@Override
	public List<?> processDetail(Resource res) {
		status=Status.LOADING;
		XlsResource xlsRes = (XlsResource) res;
		try {
			Workbook work = xlsRes.getWorkBook();
			List<?> list = xlsParse.parse(work,null);
			return list;
		} catch (Exception e) {
			log.error("load workbook exception", e);
			errMsg = e.getMessage();
			status=Status.FAILD;
		}
		return null;
	}

	@Override
	public String getErrMsg() {
		return errMsg;
	}

	@Override
	public Status getStatus() {
		return status;
	}

}
